home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / axgrid / axbutton.ctl (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-07-14  |  40.0 KB  |  942 lines

  1. VERSION 5.00
  2. Begin VB.UserControl axGridButton 
  3.    AutoRedraw      =   -1  'True
  4.    CanGetFocus     =   0   'False
  5.    ClientHeight    =   435
  6.    ClientLeft      =   0
  7.    ClientTop       =   0
  8.    ClientWidth     =   435
  9.    ScaleHeight     =   29
  10.    ScaleMode       =   3  'Pixel
  11.    ScaleWidth      =   29
  12.    ToolboxBitmap   =   "axButton.ctx":0000
  13. Attribute VB_Name = "axGridButton"
  14. Attribute VB_GlobalNameSpace = False
  15. Attribute VB_Creatable = True
  16. Attribute VB_PredeclaredId = False
  17. Attribute VB_Exposed = False
  18. Attribute VB_Ext_KEY = "PropPageWizardRun" ,"Yes"
  19. '*****************************************************************
  20. '   axButton CONTROL
  21. '   This code and control is absolutely freeware!
  22. '   You have a royalty-free right to use, modify, reproduce and distribute
  23. '   the source code and control (and/or any modified version) in any way
  24. '   you find useful, provided that you agree that the authors have no warranty,
  25. '   obligations or liability for any code distributed in this project group.
  26. '   Copyright 
  27.  1998 by Geoff Glaze
  28. '   (Some parts borrowed from Microsoft)
  29. '   If you make any improvements, the author would appreciate
  30. '   a copy of the improved source. If you include with any distribution,
  31. '   the author would appreciate notification.
  32. '   Send comments and updates to :       gglaze@transtecinc.com
  33. '   My web page (coming soon) will be :  www.cs.utexas.edu/users/gglaze
  34. '*****************************************************************
  35. Option Explicit
  36. Dim HaveCapture As Boolean
  37. Dim PaintedUp As Boolean
  38. Dim IsDown As Boolean
  39. Dim IsUp As Boolean
  40. Dim Inside As Boolean
  41. Dim ButtonVisible As Boolean
  42. 'Private mbClearURLOnly As Boolean
  43. 'Private mbClearPictureOnly As Boolean
  44. 'Private mbToolTipNotInExtender As Boolean
  45. 'Private moDrawTool As clsDrawPictures
  46. Private mbGotFocus As Boolean
  47. Private mbMouseOver As Boolean
  48. Private miCurrentState As Integer
  49. Private mWndProcNext As Long            'The address entry point for the subclassed window
  50. Private mHWndSubClassed As Long         'hWnd of the subclassed window
  51. Private mbLeftMouseDown As Boolean
  52. Private mbLeftWasDown As Boolean
  53. Private mudtButtonRect As RECT
  54. Private mudtPictureRect As RECT
  55. Private mudtPicturePoint As POINTAPI
  56. Private mbPropertiesLoaded As Boolean
  57. Private mbEnterOnce As Boolean
  58. Private mbMouseDownFired As Boolean
  59. Private mlhHalftonePal As Long
  60. Private hUpDownDitherBrush As Long
  61. Private UpDownButtonFace As Long
  62. 'Class level variables
  63. Private msToolTipBuffer As String         'Tool tip text; This string must have
  64.                                           'module or global level scope, because
  65.                                           'a pointer to it is copied into a
  66.                                           'ToolTipText structure
  67. Const cxPicture = 16
  68. Const cyPicture = 15
  69. 'Default Property Values:
  70. 'Const m_def_ToolTipText = ""
  71. Const m_def_BackStyle = 1
  72. Const m_def_BackColor = &H8000000F
  73. Const m_def_Enabled = True
  74. Const m_def_Style = 0
  75. Const m_def_Value = False
  76. Const m_def_ButtonGroup = ""
  77. Const m_def_ButtonGroupDefault = False
  78. Const m_def_ButtonGroupDefault2 = False
  79. 'Property Variables:
  80. Dim m_DownPicture As Picture
  81. Dim m_FlatPicture As Picture
  82. Dim m_DisabledPicture As Picture
  83. 'Dim m_ToolTipText As String
  84. Dim m_BackStyle As Integer
  85. Dim m_BackColor As Long
  86. Dim m_BackColorUse As Long
  87. Dim m_Picture As Picture
  88. Dim m_Enabled As Boolean
  89. Dim m_Style As Integer
  90. Dim m_Value As Boolean
  91. Dim m_ButtonGroupDefault As Boolean
  92. Dim m_ButtonGroupDefault2 As Boolean
  93. Dim m_ButtonGroup As String
  94. Public Enum PopupButtonStyle
  95.     [Toolbar Button] = 0
  96.     [Flat Button] = 1
  97.     [Separator] = 2
  98.     [Toolbar Handle] = 3
  99.     [Up-Down Button] = 4
  100.     [Standard Button] = 5
  101. End Enum
  102. Public Enum PopupButtonBackStyle
  103.     Transparent
  104.     Opaque
  105. End Enum
  106. 'Event Declarations:
  107. Event MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  108. Event Click()
  109. Attribute Click.VB_MemberFlags = "200"
  110. Private PEffect As PaintEffects
  111. Private Sub UserControl_Initialize()
  112.     Inside = False
  113.     Set PEffect = New PaintEffects
  114.     UpDownButtonFace = PEffect.AverageColors(GetSysColor(COLOR_BTNFACE), GetSysColor(COLOR_BTNHIGHLIGHT))
  115.     InitializeUpDownDither
  116. End Sub
  117. Private Sub PaintUpDownDither(x As Single, y As Single, Width As Single, Height As Single)
  118.     Dim ret As Long
  119.     Dim MyRect As RECT
  120.     'draw on the form with that brush
  121.     MyRect.Left = x
  122.     MyRect.Top = y
  123.     MyRect.Right = x + Width
  124.     MyRect.Bottom = y + Height
  125.     ret = FillRect(UserControl.hDC, MyRect, hUpDownDitherBrush)
  126. End Sub
  127. Private Sub InitializeUpDownDither()
  128.     Dim i As Long, j As Long
  129.     '---one-time setup: put this in it's own routine------
  130.     'set (invisible) picturebox properties for creating a brush
  131. '    UserControl.ScaleMode = vbPixels
  132. '    UserControl.AutoRedraw = True
  133.     'draw the dither in it
  134.     For i = 0 To UserControl.ScaleWidth - 1
  135.         For j = 0 To UserControl.ScaleHeight - 1
  136.             If (i + j) Mod 2 Then
  137.                 UserControl.PSet (i, j), vb3DHighlight
  138.             Else
  139.                 UserControl.PSet (i, j), vbButtonFace
  140.             End If
  141.         Next j
  142.     Next i
  143.     '---end of one-time setup------
  144.     'create the brush from it
  145.     hUpDownDitherBrush = CreatePatternBrush(UserControl.Image.handle)
  146. End Sub
  147. Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  148.     IsDown = True
  149.     UserControl_MouseMove Button, Shift, x, y
  150.     UserControl_Paint
  151. End Sub
  152. Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  153.     Dim NeedCapture As Boolean
  154.     On Error GoTo UserCtlMouseMoveErr
  155.     Select Case m_Style
  156.         Case [Toolbar Button], [Flat Button], [Up-Down Button], [Standard Button]
  157.             ' Is the mouse inside the control's client area?
  158.             Inside = (x > 0) And (y > 0) And (x < ScaleWidth) And (y < ScaleHeight)
  159.             If Inside And m_Enabled Then
  160.                 If PaintedUp Or (Not ButtonVisible) Then
  161.                     ButtonVisible = True
  162.                     Cls
  163.                     UserControl_Paint
  164.                 End If
  165.                 If Not ((m_Style = [Up-Down Button]) And m_Value) Then
  166.                     DrawShadowBox 0, 0, ScaleWidth, ScaleHeight, IsDown, ((m_Style = [Flat Button]) Or (m_Style = [Standard Button]))
  167.                 Else
  168.                     DrawShadowBox 0, 0, ScaleWidth, ScaleHeight, True, ((m_Style = [Flat Button]) Or (m_Style = [Standard Button]))
  169.                 End If
  170.             Else
  171.                 If IsDown And m_Enabled Then
  172.                     If Not (PaintedUp And ButtonVisible) Then
  173.                         ButtonVisible = True
  174.                         Cls
  175.                         UserControl_Paint
  176.                     End If
  177.                     DrawShadowBox 0, 0, ScaleWidth, ScaleHeight, False, ((m_Style = [Flat Button]) Or (m_Style = [Standard Button]))
  178.                 Else
  179.                     If ButtonVisible Then
  180.                         ButtonVisible = False
  181.                         Cls
  182.                         UserControl_Paint
  183.                     End If
  184.                     If Not (((m_Style = [Up-Down Button]) And m_Value) Or (m_Style = [Standard Button])) Then
  185.                         Line (0, 0)-(ScaleWidth, ScaleHeight), m_BackColorUse, B
  186.                         Line (1, 1)-(ScaleWidth - 1, ScaleHeight - 1), m_BackColorUse, B
  187.                     End If
  188.                 End If
  189.             End If
  190.             
  191.             NeedCapture = (IsDown Or (Inside And (Not IsUp))) And m_Enabled
  192.             If IsUp Then IsUp = False
  193.             
  194.             ' Set or release mouse capture if necessary
  195.             If NeedCapture And (HaveCapture = False) Then
  196.                 SetCapture hwnd
  197.                 HaveCapture = True
  198.             ElseIf (NeedCapture = False) And HaveCapture Then
  199.                 ReleaseCapture
  200.                 HaveCapture = False
  201.             End If
  202.     End Select
  203.     RaiseEvent MouseMove(Button, Shift, x, y)
  204.     Exit Sub
  205. UserCtlMouseMoveErr:
  206.     Exit Sub
  207. End Sub
  208. Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  209.     If IsDown And m_Enabled Then
  210.         If m_Style = [Up-Down Button] Then
  211.             m_Value = Not m_Value
  212.             CheckButtonGroup
  213.         End If
  214.         RaiseEvent Click
  215.     End If
  216.     IsDown = False
  217.     IsUp = True
  218.     On Error Resume Next
  219.     UserControl_MouseMove Button, Shift, -1, -1 'X, Y
  220.     UserControl_Paint
  221. End Sub
  222. Private Sub UserControl_Paint()
  223.     On Error Resume Next
  224.     Select Case m_Style
  225.         Case [Toolbar Button], [Flat Button], [Up-Down Button], [Standard Button]
  226.             PaintedUp = Not (IsDown And Inside)
  227.             If ButtonVisible Then
  228.                 If (m_Style = [Flat Button]) Or (m_Style = [Standard Button]) Then
  229.                     If PaintedUp Then
  230.                         Line (1, 1)-(ScaleWidth - 2, ScaleHeight - 2), vbButtonFace, BF
  231.                     Else
  232.                         Line (2, 2)-(ScaleWidth - 2, ScaleHeight - 2), vbButtonFace, BF
  233.                     End If
  234.                 Else
  235.                     Line (1, 1)-(ScaleWidth - 2, ScaleHeight - 2), vbButtonFace, BF
  236.                 End If
  237.             Else
  238.                 If (m_Style = [Up-Down Button]) Then
  239.                     If m_Value Then
  240.                         If Inside Then
  241.                             Line (1, 1)-(ScaleWidth - 2, ScaleHeight - 2), vbButtonFace, BF
  242.                         Else
  243.                             'use this to dither:
  244.                             PaintUpDownDither 1, 1, ScaleWidth - 2, ScaleHeight - 2
  245.                             'use this to average:
  246.                             'Line (1, 1)-(ScaleWidth - 1, ScaleHeight - 1), UpDownButtonFace, BF
  247.                         End If
  248.                         DrawShadowBox 0, 0, ScaleWidth, ScaleHeight, True, False
  249.                     Else
  250.                         Line (0, 0)-(ScaleWidth, ScaleHeight), m_BackColorUse, BF
  251.                     End If
  252.                 ElseIf (m_Style = [Standard Button]) Then
  253.                     If PaintedUp Then
  254.                         Line (1, 1)-(ScaleWidth - 2, ScaleHeight - 2), vbButtonFace, BF
  255.                     Else
  256.                         Line (2, 2)-(ScaleWidth - 1, ScaleHeight - 1), vbButtonFace, BF
  257.                     End If
  258.                     DrawShadowBox 0, 0, ScaleWidth, ScaleHeight, False, True
  259.                 Else
  260.                     Line (0, 0)-(ScaleWidth, ScaleHeight), m_BackColorUse, BF
  261.                 End If
  262.             End If
  263.             If IsAPicture(m_Picture) Then
  264.                 Dim xPixels As Long, yPixels As Long
  265.                 If m_Enabled Then
  266.                     Dim picUse As StdPicture
  267.                     If (IsDown Or ((m_Style = [Up-Down Button]) And m_Value)) And IsAPicture(m_DownPicture) Then
  268.                         Set picUse = m_DownPicture
  269.                     ElseIf Inside Or Not IsAPicture(m_FlatPicture) Then
  270.                         Set picUse = m_Picture
  271.                     Else
  272.                         Set picUse = m_FlatPicture
  273.                     End If
  274.                     xPixels = CLng(UserControl.ScaleX(picUse.Width, vbHimetric, vbPixels))
  275.                     yPixels = CLng(UserControl.ScaleY(picUse.Height, vbHimetric, vbPixels))
  276.                     PEffect.PaintTransCornerStdPic UserControl.hDC, (ScaleWidth - xPixels) / 2 + IIf(Not PaintedUp, 1, 0), (ScaleHeight - yPixels) / 2 + IIf(Not PaintedUp, 1, 0), xPixels, yPixels, picUse, 0, 0
  277. '                    PEffect.PaintGreyScaleCornerStdPic UserControl.hDC, (ScaleWidth - xPixels) / 2 + IIf(Not PaintedUp, 1, 0), (ScaleHeight - yPixels) / 2 + IIf(Not PaintedUp, 1, 0), xPixels, yPixels, picUse, 0, 0
  278.                 Else
  279.                     PaintedUp = True
  280.                     If IsAPicture(m_DisabledPicture) Then
  281.                         xPixels = CLng(UserControl.ScaleX(m_DisabledPicture.Width, vbHimetric, vbPixels))
  282.                         yPixels = CLng(UserControl.ScaleY(m_DisabledPicture.Height, vbHimetric, vbPixels))
  283.                         PEffect.PaintTransCornerStdPic UserControl.hDC, (ScaleWidth - xPixels) / 2 + IIf(Not PaintedUp, 1, 0), (ScaleHeight - yPixels) / 2 + IIf(Not PaintedUp, 1, 0), xPixels, yPixels, m_DisabledPicture, 0, 0
  284.                     Else
  285.                         xPixels = CLng(UserControl.ScaleX(m_Picture.Width, vbHimetric, vbPixels))
  286.                         yPixels = CLng(UserControl.ScaleY(m_Picture.Height, vbHimetric, vbPixels))
  287.                         PEffect.PaintDisabledCornerStdPic UserControl.hDC, (ScaleWidth - xPixels) / 2 + IIf(Not PaintedUp, 1, 0), (ScaleHeight - yPixels) / 2 + IIf(Not PaintedUp, 1, 0), xPixels, yPixels, m_Picture, 0, 0
  288.                     End If
  289.                 End If
  290.             End If
  291.         Case [Separator]
  292.             Line (0, 0)-(ScaleWidth, ScaleHeight), m_BackColorUse, BF
  293.             DrawVLine ScaleWidth \ 2 - 1, 0, 2, ScaleHeight
  294.         Case [Toolbar Handle]
  295.             Line (0, 0)-(ScaleWidth, ScaleHeight), m_BackColorUse, BF
  296.             DrawRaisedVLine ScaleWidth \ 2 - 4, 0, 3, ScaleHeight
  297.             DrawRaisedVLine ScaleWidth \ 2, 0, 3, ScaleHeight
  298.     End Select
  299. End Sub
  300. Private Function IsAPicture(pic As StdPicture) As Boolean
  301.     If (pic Is Nothing) Then
  302.         IsAPicture = False
  303.     Else
  304.         IsAPicture = (pic <> 0)
  305.     End If
  306. End Function
  307. Private Sub DrawShadowBox(ByVal x As Single, ByVal y As Single, ByVal cx As Single, ByVal cy As Single, ByVal Pressed As Boolean, ByVal DKShadow As Boolean)
  308.     If DKShadow Then
  309.         If Pressed Then
  310.             Line (x, y)-(x + cx - 1, y), vb3DDKShadow
  311.             Line (x, y)-(x, y + cy - 1), vb3DDKShadow
  312.             Line (x + 1, y + 1)-(x + cx - 2, y + 1), vbButtonShadow
  313.             Line (x + 1, y + 1)-(x + 1, y + cy - 2), vbButtonShadow
  314.             Line (x + cx - 1, y)-(x + cx - 1, y + cy), vb3DHighlight
  315.             Line (x, y + cy - 1)-(x + cx, y + cy - 1), vb3DHighlight
  316.         Else
  317.             Line (x, y)-(x + cx - 1, y), vb3DHighlight
  318.             Line (x, y)-(x, y + cy - 1), vb3DHighlight
  319.             Line (x + cx - 2, y + 1)-(x + cx - 2, y + cy - 1), vbButtonShadow
  320.             Line (x + 1, y + cy - 2)-(x + cx - 1, y + cy - 2), vbButtonShadow
  321.             Line (x + cx - 1, y)-(x + cx - 1, y + cy), vb3DDKShadow
  322.             Line (x, y + cy - 1)-(x + cx, y + cy - 1), vb3DDKShadow
  323.         End If
  324.     Else
  325.         Dim Color1 As Long
  326.         Dim Color2 As Long
  327.         If Pressed Then
  328.             Color1 = vbButtonShadow
  329.             Color2 = vb3DHighlight
  330.         Else
  331.             Color1 = vb3DHighlight
  332.             Color2 = vbButtonShadow
  333.         End If
  334.         Line (x, y)-(x + cx - 1, y), Color1
  335.         Line (x, y)-(x, y + cy - 1), Color1
  336.         Line (x + cx - 1, y)-(x + cx - 1, y + cy), Color2
  337.         Line (x, y + cy - 1)-(x + cx, y + cy - 1), Color2
  338.     End If
  339. End Sub
  340. Private Sub DrawVLine(ByVal x As Single, ByVal y As Single, ByVal cx As Single, ByVal cy As Single)
  341.     Line (x + 1, y)-(x + 1, y + cy), vb3DHighlight
  342.     Line (x, y)-(x, y + cy), vbButtonShadow
  343. End Sub
  344. Private Sub DrawRaisedVLine(ByVal x As Single, ByVal y As Single, ByVal cx As Single, ByVal cy As Single)
  345.     Line (x, y)-(x, y + cy), vb3DHighlight
  346.     Line (x + 1, y)-(x + 1, y + cy), vb3DHighlight
  347.     Line (x + 2, y)-(x + 2, y + cy), vb3DHighlight
  348.     Line (x, y + 1)-(x, y + cy), vbButtonShadow
  349.     Line (x + 1, y + 1)-(x + 1, y + cy), vbButtonShadow
  350.     Line (x + 2, y + 1)-(x + 2, y + cy), vbButtonShadow
  351.     Line (x, y)-(x, y + cy - 1), vb3DHighlight
  352.     Line (x + 1, y + 1)-(x + 1, y + cy - 1), vbButtonFace
  353. End Sub
  354. 'Load property values from storage
  355. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  356.     On Error Resume Next
  357.     Set m_Picture = PropBag.ReadProperty("Picture", Nothing)
  358.     m_Enabled = PropBag.ReadProperty("Enabled", m_def_Enabled)
  359.     m_Style = PropBag.ReadProperty("Style", m_def_Style)
  360.     m_Value = PropBag.ReadProperty("Value", m_def_Value)
  361.     m_ButtonGroup = PropBag.ReadProperty("ButtonGroup", m_def_ButtonGroup)
  362.     m_ButtonGroupDefault = PropBag.ReadProperty("ButtonGroupDefault", m_def_ButtonGroupDefault)
  363.     m_ButtonGroupDefault2 = PropBag.ReadProperty("ButtonGroupDefault2", m_def_ButtonGroupDefault2)
  364.     m_BackStyle = PropBag.ReadProperty("BackStyle", m_def_BackStyle)
  365. '    m_BackColor = PropBag.ReadProperty("BackColor", UserControl.Extender.Container.BackColor)
  366.     m_BackColor = PropBag.ReadProperty("BackColor", m_def_BackColor)
  367.     SetBackColor
  368. '    m_ToolTipText = PropBag.ReadProperty("ToolTipText", m_def_ToolTipText)
  369. '    ToolTipText = m_ToolTipText
  370.     Set m_DownPicture = PropBag.ReadProperty("DownPicture", Nothing)
  371.     Set m_FlatPicture = PropBag.ReadProperty("FlatPicture", Nothing)
  372.     Set m_DisabledPicture = PropBag.ReadProperty("DisabledPicture", Nothing)
  373.     InstanciateToolTipsWindow
  374. End Sub
  375. Private Sub UserControl_Resize()
  376.     UserControl_Paint
  377. End Sub
  378. Private Sub UserControl_Show()
  379.     UserControl_Paint
  380. End Sub
  381. Private Sub UserControl_Terminate()
  382.     Set PEffect = Nothing
  383.     glToolsCount = glToolsCount - 1
  384.     UnSubClass
  385.     If gbToolTipsInstanciated And glToolsCount = 0 Then
  386.         DestroyWindow gHWndToolTip
  387.     End If
  388.     'clean up
  389.     Call DeleteObject(hUpDownDitherBrush)
  390. End Sub
  391. 'Write property values to storage
  392. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  393.     Call PropBag.WriteProperty("Picture", m_Picture, Nothing)
  394.     Call PropBag.WriteProperty("Enabled", m_Enabled, m_def_Enabled)
  395.     Call PropBag.WriteProperty("Style", m_Style, m_def_Style)
  396.     Call PropBag.WriteProperty("Value", m_Value, m_def_Value)
  397.     Call PropBag.WriteProperty("ButtonGroup", m_ButtonGroup, m_def_ButtonGroup)
  398.     Call PropBag.WriteProperty("ButtonGroupDefault", m_ButtonGroupDefault, m_def_ButtonGroupDefault)
  399.     Call PropBag.WriteProperty("ButtonGroupDefault2", m_ButtonGroupDefault2, m_def_ButtonGroupDefault2)
  400.     Call PropBag.WriteProperty("BackStyle", m_BackStyle, m_def_BackStyle)
  401.     Call PropBag.WriteProperty("BackColor", m_BackColor, UserControl.Extender.Container.BackColor)
  402. '    Call PropBag.WriteProperty("BackColor", m_BackColor, m_def_BackColor)
  403. '    Call PropBag.WriteProperty("ToolTipText", m_ToolTipText, m_def_ToolTipText)
  404.     Call PropBag.WriteProperty("DownPicture", m_DownPicture, Nothing)
  405.     Call PropBag.WriteProperty("FlatPicture", m_FlatPicture, Nothing)
  406.     Call PropBag.WriteProperty("DisabledPicture", m_DisabledPicture, Nothing)
  407. End Sub
  408. Public Property Get Picture() As Picture
  409.     Set Picture = m_Picture
  410. End Property
  411. Public Property Set Picture(ByVal New_Picture As Picture)
  412.     Set m_Picture = New_Picture
  413.     If m_Enabled Then
  414.         Cls
  415.         UserControl_Paint
  416.     End If
  417.     PropertyChanged "Picture"
  418. End Property
  419. Public Property Get DownPicture() As Picture
  420.     Set DownPicture = m_DownPicture
  421. End Property
  422. Public Property Set DownPicture(ByVal New_DownPicture As Picture)
  423.     Set m_DownPicture = New_DownPicture
  424.     If m_Enabled Then
  425.         Cls
  426.         UserControl_Paint
  427.     End If
  428.     PropertyChanged "DownPicture"
  429. End Property
  430. Public Property Get FlatPicture() As Picture
  431.     Set FlatPicture = m_FlatPicture
  432. End Property
  433. Public Property Set FlatPicture(ByVal New_FlatPicture As Picture)
  434.     Set m_FlatPicture = New_FlatPicture
  435.     If m_Enabled Then
  436.         Cls
  437.         UserControl_Paint
  438.     End If
  439.     PropertyChanged "FlatPicture"
  440. End Property
  441. Public Property Get DisabledPicture() As Picture
  442.     Set DisabledPicture = m_DisabledPicture
  443. End Property
  444. Public Property Set DisabledPicture(ByVal New_DisabledPicture As Picture)
  445.     Set m_DisabledPicture = New_DisabledPicture
  446.     If Not m_Enabled Then
  447.         Cls
  448.         UserControl_Paint
  449.     End If
  450.     PropertyChanged "DisabledPicture"
  451. End Property
  452. 'Initialize Properties for User Control
  453. Private Sub UserControl_InitProperties()
  454.     Set m_Picture = LoadPicture("")
  455.     Set m_FlatPicture = LoadPicture("")
  456.     Set m_DownPicture = LoadPicture("")
  457.     Set m_DisabledPicture = LoadPicture("")
  458.     m_Value = m_def_Value
  459.     m_ButtonGroup = m_def_ButtonGroup
  460.     m_ButtonGroupDefault = m_def_ButtonGroupDefault
  461.     m_ButtonGroupDefault2 = m_def_ButtonGroupDefault2
  462.     m_Enabled = m_def_Enabled
  463.     m_Style = m_def_Style
  464.     m_BackStyle = m_def_BackStyle
  465.     m_BackColor = UserControl.Extender.Container.BackColor
  466. '    m_BackColor = m_def_BackColor
  467.     SetBackColor
  468. '    m_ToolTipText = m_def_ToolTipText
  469. '    UserControl.Extender.ToolTipText = m_ToolTipText
  470.     UserControl_Resize
  471. End Sub
  472. Public Property Get ButtonGroup() As String
  473.     ButtonGroup = m_ButtonGroup
  474. End Property
  475. Public Property Let ButtonGroup(ByVal New_ButtonGroup As String)
  476.     If Not (m_ButtonGroup = New_ButtonGroup) Then
  477.         m_ButtonGroup = New_ButtonGroup
  478.         If m_Style = [Up-Down Button] Then
  479.             CheckButtonGroup
  480.             Cls
  481.             UserControl_Paint
  482.         End If
  483.     End If
  484.     PropertyChanged "ButtonGroup"
  485. End Property
  486. Public Property Get ButtonGroupDefault() As Boolean
  487.     ButtonGroupDefault = m_ButtonGroupDefault
  488. End Property
  489. Public Property Let ButtonGroupDefault(ByVal New_ButtonGroupDefault As Boolean)
  490.     'The following line of code ensures that the integer
  491.     'value of the boolean parameter is either
  492.     '0 or -1.  It is known that Access 97 will
  493.     'set the boolean's value to 255 for true.
  494.     'In this case a P-Code compiled VB5 built
  495.     'OCX will return True for the expression
  496.     '(Not [boolean variable that ='s 255]).  This
  497.     'line ensures the reliability of boolean operations
  498.     If CBool(New_ButtonGroupDefault) Then New_ButtonGroupDefault = True Else New_ButtonGroupDefault = False
  499.     If Not (m_ButtonGroupDefault = New_ButtonGroupDefault) Then
  500.         m_ButtonGroupDefault = New_ButtonGroupDefault
  501.         If m_Style = [Up-Down Button] Then
  502.             CheckButtonGroupDefault
  503.             CheckButtonGroup
  504.             Cls
  505.             UserControl_Paint
  506.         End If
  507.     End If
  508.     PropertyChanged "ButtonGroupDefault"
  509. End Property
  510. Private Sub CheckButtonGroupDefault()
  511.     If (Len(m_ButtonGroup) > 0) Then
  512.         If m_ButtonGroupDefault Then     ' make all others in group not default
  513.             Dim ctl As Control
  514.             Dim i As Long
  515.             For i = 0 To UserControl.ParentControls.Count - 1
  516.                 If TypeOf UserControl.ParentControls(i) Is Control Then
  517.                     Set ctl = UserControl.ParentControls(i)
  518.                     If TypeOf ctl Is axGridButton Then
  519.                         If ctl.ButtonGroup = m_ButtonGroup Then
  520.                             If Not ((ctl Is UserControl.Extender) Or (ctl Is UserControl)) Then
  521.                                 ctl.ButtonGroupDefault = False
  522.                             End If
  523.                         End If
  524.                     End If
  525.                 End If
  526.             Next
  527.         End If
  528.     End If
  529. End Sub
  530. Public Property Get ButtonGroupDefault2() As Boolean
  531.     ButtonGroupDefault2 = m_ButtonGroupDefault2
  532. End Property
  533. Public Property Let ButtonGroupDefault2(ByVal New_ButtonGroupDefault2 As Boolean)
  534.     'The following line of code ensures that the integer
  535.     'value of the boolean parameter is either
  536.     '0 or -1.  It is known that Access 97 will
  537.     'set the boolean's value to 255 for true.
  538.     'In this case a P-Code compiled VB5 built
  539.     'OCX will return True for the expression
  540.     '(Not [boolean variable that ='s 255]).  This
  541.     'line ensures the reliability of boolean operations
  542.     If CBool(New_ButtonGroupDefault2) Then New_ButtonGroupDefault2 = True Else New_ButtonGroupDefault2 = False
  543.     If Not (m_ButtonGroupDefault2 = New_ButtonGroupDefault2) Then
  544.         m_ButtonGroupDefault2 = New_ButtonGroupDefault2
  545.         If m_Style = [Up-Down Button] Then
  546.             CheckButtonGroupDefault2
  547.             CheckButtonGroup
  548.             Cls
  549.             UserControl_Paint
  550.         End If
  551.     End If
  552.     PropertyChanged "ButtonGroupDefault2"
  553. End Property
  554. Private Sub CheckButtonGroupDefault2()
  555.     If (Len(m_ButtonGroup) > 0) Then
  556.         If m_ButtonGroupDefault2 Then     ' make all others in group not default
  557.             Dim ctl As Control
  558.             Dim i As Long
  559.             For i = 0 To UserControl.ParentControls.Count - 1
  560.                 If TypeOf UserControl.ParentControls(i) Is Control Then
  561.                     Set ctl = UserControl.ParentControls(i)
  562.                     If TypeOf ctl Is axGridButton Then
  563.                         If ctl.ButtonGroup = m_ButtonGroup Then
  564.                             If Not ((ctl Is UserControl.Extender) Or (ctl Is UserControl)) Then
  565.                                 ctl.ButtonGroupDefault2 = False
  566.                             End If
  567.                         End If
  568.                     End If
  569.                 End If
  570.             Next
  571.         End If
  572.     End If
  573. End Sub
  574. Private Sub CheckButtonGroup()
  575.     If (Len(m_ButtonGroup) > 0) Then
  576.         Dim ctl As Control
  577.         Dim i As Long
  578.         If m_Value Then     ' clear all others in group
  579.             For i = 0 To UserControl.ParentControls.Count - 1
  580.                 If TypeOf UserControl.ParentControls(i) Is Control Then
  581.                     Set ctl = UserControl.ParentControls(i)
  582.                     If TypeOf ctl Is axGridButton Then
  583.                         If ctl.ButtonGroup = m_ButtonGroup Then
  584.                             If Not ((ctl Is UserControl.Extender) Or (ctl Is UserControl)) Then
  585.                                 ctl.Value = False
  586.                             End If
  587.                         End If
  588.                     End If
  589.                 End If
  590.             Next
  591.         Else                 ' set group default if necessary
  592.             Dim GroupValueSet As Boolean
  593.             Dim ctlDefault As axGridButton
  594.             Dim ctlDefault2 As axGridButton
  595.             Set ctlDefault = Nothing
  596.             Set ctlDefault2 = Nothing
  597.             GroupValueSet = False
  598.             For i = 0 To UserControl.ParentControls.Count - 1
  599.                 If TypeOf UserControl.ParentControls(i) Is Control Then
  600.                     Set ctl = UserControl.ParentControls(i)
  601.                     If TypeOf ctl Is axGridButton Then
  602.                         If ctl.ButtonGroup = m_ButtonGroup Then
  603. '                            If Not ((ctl Is UserControl.Extender) Or (ctl Is UserControl)) Then
  604.                                 If ctl.Value Then
  605.                                     GroupValueSet = True
  606.                                     Exit For
  607.                                 ElseIf ctl.ButtonGroupDefault Then
  608.                                     Set ctlDefault = ctl
  609.                                 ElseIf ctl.ButtonGroupDefault2 Then
  610.                                     Set ctlDefault2 = ctl
  611.                                 End If
  612. '                            End If
  613.                         End If
  614.                     End If
  615.                 End If
  616.             Next
  617.             If Not (GroupValueSet Or (ctlDefault Is Nothing)) Then
  618.                 If (Not m_ButtonGroupDefault) Or (ctlDefault2 Is Nothing) Then
  619.                     ctlDefault.Value = True
  620.                 Else
  621.                     ctlDefault2.Value = True
  622.                 End If
  623.             End If
  624.         End If
  625.     End If
  626. End Sub
  627. Public Property Get Value() As Boolean
  628.     Value = m_Value
  629. End Property
  630. Public Property Let Value(ByVal New_Value As Boolean)
  631.     'The following line of code ensures that the integer
  632.     'value of the boolean parameter is either
  633.     '0 or -1.  It is known that Access 97 will
  634.     'set the boolean's value to 255 for true.
  635.     'In this case a P-Code compiled VB5 built
  636.     'OCX will return True for the expression
  637.     '(Not [boolean variable that ='s 255]).  This
  638.     'line ensures the reliability of boolean operations
  639.     If CBool(New_Value) Then New_Value = True Else New_Value = False
  640.     If Not (m_Value = New_Value) Then
  641.         m_Value = New_Value
  642.         If m_Style = [Up-Down Button] Then
  643.             CheckButtonGroup
  644.             Cls
  645.             UserControl_Paint
  646.         End If
  647.     End If
  648.     PropertyChanged "Value"
  649. End Property
  650. Public Property Get Enabled() As Boolean
  651.     Enabled = m_Enabled
  652. End Property
  653. Public Property Let Enabled(ByVal New_Enabled As Boolean)
  654.     'The following line of code ensures that the integer
  655.     'value of the boolean parameter is either
  656.     '0 or -1.  It is known that Access 97 will
  657.     'set the boolean's value to 255 for true.
  658.     'In this case a P-Code compiled VB5 built
  659.     'OCX will return True for the expression
  660.     '(Not [boolean variable that ='s 255]).  This
  661.     'line ensures the reliability of boolean operations
  662.     If CBool(New_Enabled) Then New_Enabled = True Else New_Enabled = False
  663.     If Not (m_Enabled = New_Enabled) Then
  664.         m_Enabled = New_Enabled
  665.         Inside = False
  666.         Cls
  667.         UserControl_Paint
  668.     End If
  669.     PropertyChanged "Enabled"
  670. End Property
  671. Public Property Get Style() As PopupButtonStyle
  672.     Style = m_Style
  673. End Property
  674. Public Property Let Style(ByVal New_Style As PopupButtonStyle)
  675.     If Not (m_Style = New_Style) Then
  676.         m_Style = New_Style
  677.         Cls
  678.         UserControl_Paint
  679.     End If
  680.     PropertyChanged "Style"
  681. End Property
  682. Public Property Get BackStyle() As PopupButtonBackStyle
  683.     BackStyle = m_BackStyle
  684. End Property
  685. Public Property Let BackStyle(ByVal New_BackStyle As PopupButtonBackStyle)
  686.     If Not (m_BackStyle = New_BackStyle) Then
  687.         m_BackStyle = New_BackStyle
  688.         SetBackColor
  689.         Cls
  690.         UserControl_Paint
  691.     End If
  692.     PropertyChanged "BackStyle"
  693. End Property
  694. Public Property Get BackColor() As OLE_COLOR
  695.     BackColor = m_BackColor
  696. End Property
  697. Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
  698.     If Not (m_BackColor = New_BackColor) Then
  699.         m_BackColor = New_BackColor
  700.         SetBackColor
  701.         Cls
  702.         UserControl_Paint
  703.     End If
  704.     PropertyChanged "BackColor"
  705. End Property
  706. Private Sub SetBackColor()
  707.     If (m_BackStyle = Opaque) Then
  708.         m_BackColorUse = m_BackColor
  709.     Else
  710.         m_BackColorUse = UserControl.Extender.Container.BackColor
  711.     End If
  712. End Sub
  713. 'Public Property Get ToolTipText() As String
  714. '    ToolTipText = m_ToolTipText
  715. 'End Property
  716. 'Public Property Let ToolTipText(ByVal New_ToolTipText As String)
  717. '    MsgBox "let : " & New_ToolTipText
  718. '    m_ToolTipText = New_ToolTipText
  719. ''    UserControl.Extender.ToolTipText = m_ToolTipText
  720. '    PropertyChanged "ToolTipText"
  721. 'End Property
  722. '*************************
  723. 'Private Procedures
  724. '*************************
  725. 'Private Sub MakeClick()
  726. '    '-------------------------------------------------------------------------
  727. '    'Purpose:   Raise a Click event to container, play sound
  728. '    '-------------------------------------------------------------------------
  729. '    '-----------------------------------------
  730. '    '- Added for sound support
  731. '    '-----------------------------------------
  732. '    If m_bPlaySounds Then PlaySound EVENT_MENU_COMMAND, 0, SND_SYNC
  733. '    '-----------------------------------------
  734. '    RaiseEvent Click
  735. 'End Sub
  736. 'Private Sub MouseOver()
  737. '    '-------------------------------------------------------------------------
  738. '    'Purpose:   Call whenever the mouse is over the button and
  739. '    '           button needs raised appearance and capture set
  740. '    '-------------------------------------------------------------------------
  741. '    If miCurrentState <> giRAISED Then DrawButtonState giRAISED
  742. '    If Not mbMouseOver Then
  743. '        Capture True
  744. '        mbMouseOver = True
  745. '        '-----------------------------------------
  746. '        '- Added for sound support
  747. '        '-----------------------------------------
  748. '        If Not mbEnterOnce Then
  749. '            RaiseEvent PopUp
  750. '            If m_bPlaySounds Then PlaySound EVENT_MENU_POPUP, 0, SND_SYNC
  751. '            mbEnterOnce = True
  752. '        End If
  753. '        '-----------------------------------------
  754. '    End If
  755. 'End Sub
  756. 'Private Sub Flatten()
  757. '    '-------------------------------------------------------------------------
  758. '    'Purpose:   Call whenever the mouse is off the control
  759. '    '           and capture needs released and button needs
  760. '    '           flattened appearance
  761. '    '-------------------------------------------------------------------------
  762. '    If mbMouseOver Then Capture False
  763. '    mbMouseOver = False
  764. '    If (Not mbGotFocus) And miCurrentState <> giFLATTENED Then DrawButtonState giFLATTENED
  765. '    '-----------------------------------------
  766. '    '- Added for sound support
  767. '    '-----------------------------------------
  768. '    '   PlaySound EVENT_MENU_POPUP, 0, SND_SYNC
  769. '    mbEnterOnce = False
  770. '    '-----------------------------------------
  771. 'End Sub
  772. 'Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
  773. '    On Error GoTo ErrorHandler
  774. '    If (AsyncProp.PropertyName = msPICTURE_NAME) Then ' Picture download is complete
  775. '        mbClearPictureOnly = True
  776. '        Set Picture = AsyncProp.Value           ' Store picture data to property...
  777. '    End If
  778. 'ErrorHandler:
  779. '    mbClearPictureOnly = False
  780. 'End Sub
  781. Private Sub AddTool(hwnd As Long)
  782.     '-------------------------------------------------------------------------
  783.     'Purpose:   Add a tool to the ToolTips object
  784.     'In:        [hWnd]
  785.     '               hWnd of Tool being added
  786.     '-------------------------------------------------------------------------
  787.                    
  788.     Dim ti As TOOLINFO
  789.     With ti
  790.         .cbSize = Len(ti)
  791.         .uId = hwnd
  792.         .hwnd = hwnd
  793.         .hinst = App.hInstance
  794.         .uFlags = TTF_IDISHWND
  795.         .lpszText = LPSTR_TEXTCALLBACK
  796.     End With
  797.     SendMessage gHWndToolTip, TTM_ADDTOOL, 0, ti
  798.     SendMessage gHWndToolTip, TTM_ACTIVATE, 1, ByVal hwnd
  799.     Exit Sub
  800. End Sub
  801. Private Sub InstanciateToolTipsWindow()
  802.     '-------------------------------------------------------------------------
  803.     'Purpose:   Instanciate needed collections.
  804.     '           Create ToolTips Class window
  805.     '-------------------------------------------------------------------------
  806.     glToolsCount = glToolsCount + 1
  807.     If Not (TypeOf UserControl.Extender.Parent Is axGrid) Then Exit Sub
  808.     If UserControl.Extender.Parent.Ambient.UserMode Then
  809.         If Not gbToolTipsInstanciated Then
  810.             gbToolTipsInstanciated = True
  811.             InitCommonControls
  812.             gHWndToolTip = CreateWindowEX(WS_EX_TOPMOST, TOOLTIPS_CLASS, vbNullString, 0, _
  813.                       CW_USEDEFAULT, CW_USEDEFAULT, _
  814.                       CW_USEDEFAULT, CW_USEDEFAULT, _
  815.                       0, 0, _
  816.                       App.hInstance, _
  817.                       ByVal 0)
  818.             SendMessage gHWndToolTip, TTM_ACTIVATE, 1, ByVal 0
  819.             
  820.             #If DEBUGSUBCLASS Then
  821.                 If goWindowProcHookCreator Is Nothing Then Set goWindowProcHookCreator = CreateObject("DbgWindowProc.WindowProcHookCreator")
  822.             #End If
  823.         End If
  824.         'Sub class this code module to receive
  825.         'window messages for the Usercontrol
  826.         SubClass UserControl.hwnd
  827.         'Add Register Usercontrol with ToolTip window
  828.         AddTool UserControl.hwnd
  829.     End If
  830. End Sub
  831. Private Sub SubClass(hwnd)
  832.     '-------------------------------------------------------------------------
  833.     'Purpose:   Subclass control so that the ToolTip Need text message can be
  834.     '           handled.  Store handle of class as UserData of control window
  835.     '-------------------------------------------------------------------------
  836.     Dim lresult As Long
  837.     UnSubClass
  838.     #If DEBUGSUBCLASS Then
  839.         'If in debug, SubClass window using address of WindowProcHook
  840.         'Let WindowProcHook CallWindowProc at address of my function
  841.         'if in run mode but call the previous address if in break mode
  842.         'this prevents crashes in break mode
  843.         Set moProcHook = goWindowProcHookCreator.CreateWindowProcHook
  844.         With moProcHook
  845.             .SetMainProc AddressOf SubWndProc
  846.             mWndProcNext = SetWindowLong(hwnd, GWL_WNDPROC, CLng(.ProcAddress))
  847.             .SetDebugProc mWndProcNext
  848.         End With
  849.     #Else
  850.         mWndProcNext = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubWndProc)
  851.     #End If
  852.     If mWndProcNext Then
  853.         mHWndSubClassed = hwnd
  854.         lresult = SetWindowLong(hwnd, GWL_USERDATA, ObjPtr(Me))
  855.     End If
  856. End Sub
  857. Private Sub UnSubClass()
  858.     '-------------------------------------------------------------------------
  859.     'Purpose:   Unsubclass control
  860.     '-------------------------------------------------------------------------
  861.     If mWndProcNext Then
  862.         SetWindowLong mHWndSubClassed, GWL_WNDPROC, mWndProcNext
  863.         mWndProcNext = 0
  864.         
  865.         #If DEBUGSUBCLASS Then
  866.             Set moProcHook = Nothing
  867.         #End If
  868.         
  869.     End If
  870. End Sub
  871. '*************************
  872. 'Friend Methods
  873. '*************************
  874. Friend Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  875.     '-------------------------------------------------------------------------
  876.     'Purpose:   Handles window messages specific to subclassed window associated
  877.     '           with this object.  Is called by SubWndProc in standard module.
  878.     '           Relays all mouse messages to ToolTip window, and returns a value
  879.     '           for ToolTip NeedText message.
  880.     '-------------------------------------------------------------------------
  881.     Dim msgStruct As MSG
  882.     Dim hdr As NMHDR
  883.     Dim ttt As ToolTipText
  884.     On Error GoTo WindowProc_Error
  885.     Select Case uMsg
  886.         Case WM_MOUSEMOVE, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP
  887.             With msgStruct
  888.                 .lParam = lParam
  889.                 .wParam = wParam
  890.                 .message = uMsg
  891.                 .hwnd = hwnd
  892.             End With
  893.             If m_Enabled Then
  894.                 SendMessage gHWndToolTip, TTM_RELAYEVENT, 0, msgStruct
  895.             End If
  896.         Case WM_NOTIFY
  897.             CopyMemory hdr, ByVal lParam, Len(hdr)
  898.             If hdr.code = TTN_NEEDTEXT And hdr.hwndFrom = gHWndToolTip Then
  899.                 'Get the tooltip text from the UserControl class object
  900.                 'If the host for this control provides a ToolTipText property
  901.                 'on the extender object (as in VB5).  The ToolTipText property
  902.                 'declares will not be hit.  Therefore, the user's ToolTipText
  903.                 'may be found either in the Extender.ToolTipText property or
  904.                 'in my own member variable m_sToolTipText
  905.                 'Error may occur if ToolTipText property is not available
  906.                 'On Error Resume Next
  907. '                If mbToolTipNotInExtender Then
  908. '                    msToolTipBuffer = StrConv(m_sToolTipText, vbFromUnicode)
  909. '                Else
  910. '                    msToolTipBuffer = StrConv(UserControl.Extender.ToolTipText, vbFromUnicode)
  911. '                End If
  912. '                msToolTipBuffer = "safsaf"
  913.                 msToolTipBuffer = StrConv(UserControl.Extender.ToolTipText, vbFromUnicode)
  914. '                Debug.Print " > " & msToolTipBuffer & " : " & m_ToolTipText & " : " & UserControl.Extender.ToolTipText
  915.                 If Err.Number = 0 Then
  916.                     CopyMemory ttt, ByVal lParam, Len(ttt)
  917.                     ttt.lpszText = StrPtr(msToolTipBuffer)
  918.                     CopyMemory ByVal lParam, ttt, Len(ttt)
  919.                 End If
  920.             End If
  921.         Case WM_CANCELMODE
  922.             'A window has been put over this one
  923.             'flatten the button
  924. '            Flatten
  925.             mbGotFocus = False
  926.             mbLeftMouseDown = False
  927.             mbLeftWasDown = False
  928.             mbMouseDownFired = False
  929.     End Select
  930. WindowProc_Resume:
  931.     WindowProc = CallWindowProc(mWndProcNext, hwnd, uMsg, wParam, ByVal lParam)
  932.     Exit Function
  933. WindowProc_Error:
  934.     Resume WindowProc_Resume
  935. End Function
  936. Sub ShowAboutBox()
  937. Attribute ShowAboutBox.VB_UserMemId = -552
  938.   frmAbout.Show vbModal
  939.   Unload frmAbout
  940.   Set frmAbout = Nothing
  941. End Sub
  942.